﻿// Copyright (C) Norsolutions GmbH
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Reng van Oord
// Created:    2010.05.05


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sherwood.Mvc.Html
{
    /// <summary>
    /// Provides a culture list source for an ASP.Net MVC drop down list.
    /// Value is the .Net culture code and text is the name in English.
    /// </summary>
    public class MediumCultureSelectList
    {
        public static List<SelectListItem> GetList(object selectedValue, bool translate)
        {
            if (selectedValue == null)
            {
                selectedValue = "en-US";
            }
            string[] values = new string[] { 
"af-ZA","Afrikaans",
"bg-BG","Bulgarian",
"zh-CN","Chinese (Simplified)",
"zh-HK","Chinese (Traditional)",
"hr-HR","Croatian - Croatia",
"da-DK","Danish",
"nl-NL","Dutch",
"en-US","English",
"fi-FI","Finnish",
"fr-FR","French",
"de-DE","German",
"he-IL","Hebrew",
"hi-IN","Hindi",
"hu-HU","Hungarian",
"id-ID","Indonesian",
"it-IT","Italian",
"nb-NO","Norwegian",
"pl-PL","Polish",
"pt-PT","Portuguese",
"ro-RO","Romanian",
"ru-RU","Russian",
"sa-IN","Sanskrit",
"sr-Latn-RS","Serbian",
"es-ES","Spanish",
"sv-SE","Swedish",
"tr-TR","Turkish" };

            List<SelectListItem> items = new List<SelectListItem>();

            for (int i = 0; i < values.Length; i = i + 2)
            {
                SelectListItem item = new SelectListItem();
                if (translate)
                    item.Text = "[!" + values[i + 1] + "!]";
                else
                    item.Text = values[i + 1];
                item.Value = values[i];
                item.Selected = selectedValue != null && values[i].Equals(selectedValue.ToString(), StringComparison.OrdinalIgnoreCase);
                items.Add(item);
            }

            return items;
        }
    }
}
